
// 设计用户的表模型
const mongoose = require('mongoose')
const Schema = mongoose.Schema
//设计文章的表模型
const NoteSchema = new Schema({
    author: {
        type: Schema.Types.ObjectId,
        ref: 'User', //表关联
        require: true
    },
    content: {
        type: String,
        require: true,
    },
    imgList: {
        type: Array,
        require: false,
    },
    pv: {
        type: Number,
        default: 0
    },
    key: {
        type: Array,
        default: []
    },
    // 点赞人数
    like: {
        type: Array,
        default: []
    },
    // 评论条数
    comments: [{
        words: {
            type: String,
            require: true
        },
        leaver: {
            type: Schema.Types.ObjectId,
            ref: 'User', //表关联
            require: true
        },
        time: {
            type: String,
            default: ''
        }
    }],
    // 发布时间
    createTime: { //初次保存时的时间
        type: String,
        default: ''
    },
    // 地点
    place: {
        type: String,
        default: ''
    },

    tag: {
        type: String,
        default: ''
    },
    // 标题
    title: {
        type: String,
        default: ''
    },
    isPass: {
        type: Boolean,
        default: false
    }
})
// NoteSchema.pre('save',function(next){ //监听文章是否初次保存
//     if(this.isNew){
//         this.meta.createAt = this.meta.updateAt = Date.now()
//     }else{
//         this.meta.updateAt = Date.now()
//     }
//     next() //开启后续代码才可执行
// })

module.exports = mongoose.model('NoteSchema', NoteSchema)